/*  
*   This file is a part of Neutrino - a lightweight UI library accelerated with OpenGL
*   Copyright (C) 2023 bsolos
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <GLFW/glfw3.h>
#include <memory>

namespace neutrino {
    class window_surface;

    class render_context {
    public:
        void main_loop();

        void mark_for_present();

        void set_width(int width);
        void set_height(int height);
        void set_size(int width, int height);

        window_surface create_surface();

        static render_context *create();
        static void destroy(render_context *ctx);

    private:
        GLFWwindow *glfw_window;
        int width, height;

        bool clear_buffer = true;
        bool do_present = true;

        render_context();
        ~render_context();

        void render_incremental();
        void render_clear();
        void present();

        static void framebuffer_size_callback(GLFWwindow* window, int width, int height);
        void on_framebuffer_size_changed(int width, int height);
    };
}